import 'package:xr_base/string_constants.dart';
import 'package:xr_cache/xr_cache.dart';

import '../models/account.dart';

class XrCacheUtil {
  /// token
  static setToken(String token) => XrCache.getInstance().setString(Strings.login_user_token, token);

  static get token => XrCache.getInstance().getString(Strings.login_user_token);

  static removeToken() => XrCache.getInstance().remove(Strings.login_user_token);

  /// Account
  static setAccount(Object obj) => XrCacheUtil.setObject(Strings.login_user_info, obj);

  static AccountData? get account =>
      XrCache.getInstance().getObject(Strings.login_user_info, (v) => AccountData.fromJson(v));

  static removeAccount() => XrCache.getInstance().remove(Strings.login_user_info);

  static Future<bool> setString(String key, String value) {
    return XrCache.getInstance().setString(key, value);
  }

  static Future<bool> setObject(String key, Object value) {
    return XrCache.getInstance().setObject(key, value);
  }

  static remove(String key) => XrCache.getInstance().remove(key);
}
